// $Id$
package de.servicezombie.pub.r1;

import java.util.Collections;
import java.util.LinkedList;
import java.util.List;

import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlType;

import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;

@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "", propOrder = {
		"errors", "warnings", "infos", "debugs"
})
@XmlRootElement(name = "messages", namespace = XmlNamespaces.SERVICEZOMBIE_COMMON)
public class MessageContainer {

	@XmlElement(required = true)
	private List<Message> errors = new LinkedList<Message>();
	
	@XmlElement(required = true)
	private List<Message> warnings = new LinkedList<Message>();
	
	@XmlElement(required = true)
	private List<Message> infos = new LinkedList<Message>();
	
	@XmlElement(required = true)
	private List<Message> debugs = new LinkedList<Message>();

	protected MessageContainer() {}
	
	public void clearAll() {
		errors.clear();
		warnings.clear();
		infos.clear();
		debugs.clear();
	}

	public void addError(Message message) {
		errors.add(message);
	}

	public void addWarning(Message message) {
		warnings.add(message);
	}

	public void addInfo(Message message) {
		infos.add(message);
	}

	public void addDebug(Message message) {
		debugs.add(message);
	}

	public List<Message> getErrors() {
		return Collections.unmodifiableList(errors);
	}

	public List<Message> getWarnings() {
		return Collections.unmodifiableList(warnings);
	}

	public List<Message> getInfos() {
		return Collections.unmodifiableList(infos);
	}

	public List<Message> getDebugs() {
		return Collections.unmodifiableList(debugs);
	}

	// for testing purposes
	public boolean isEmpty() {
		return errors.isEmpty() && warnings.isEmpty() && infos.isEmpty() && debugs.isEmpty();
	}
	
	@Override
	public String toString() {
		return new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE)
				.append("errors", errors)
				.append("warnings", warnings)
				.append("info", infos)
				.append("debugcount", debugs.size())
				.toString();
	}

}
